package org.hcyspartnoc.demo.service.traProgram.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.hcyspartnoc.demo.mapper.major.MajorMapper;
import org.hcyspartnoc.demo.pojo.po.major.MajorPo;
import org.hcyspartnoc.demo.pojo.vo.traProgram.MajorVo;
import org.hcyspartnoc.demo.service.traProgram.IMajorService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class MajorServiceImpl extends ServiceImpl<MajorMapper, MajorPo> implements IMajorService {
    @Resource
    private MajorMapper majorMapper;

    @Override
    @Transactional
    public List<MajorVo> getMajors() {
        List<MajorPo> majors = majorMapper.selectList(null);
        List<MajorVo> majorVoList = new ArrayList<>();
        for(MajorPo majorPo : majors){
            MajorVo majorVo = new MajorVo();
            BeanUtils.copyProperties(majorPo, majorVo); // 复制属性
            majorVoList.add(majorVo);
        }
        return majorVoList;
    }

}
